package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.pojo.dto.SlideshowQueryDto;
import com.example.pojo.entity.Slideshow;
import com.example.pojo.vo.SlideshowQueryVo;
import com.example.service.SlideshowService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 轮播图 controller 层
 */
@RestController
@RequestMapping("/slideshow")
public class SlideshowController {

    @Resource
    private SlideshowService slideshowService;

    @PostMapping("/add")
    public Result add(@RequestBody Slideshow slideshow) {
        this.slideshowService.add(slideshow);
        return Result.success();
    }

    @GetMapping("/pageQuery")
    public Result pageQuery(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            SlideshowQueryDto dto
    ) {
        PageResult<SlideshowQueryVo> pageResult = this.slideshowService.pageQuery(pageNum, pageSize, dto);
        return Result.success(pageResult);
    }

    @GetMapping("/query")
    public Result queryById(@RequestParam Integer id) {
        SlideshowQueryVo slideshow = this.slideshowService.queryById(id);
        return Result.success(slideshow);
    }

    @GetMapping("/query/all")
    public Result queryAll() {
        List<SlideshowQueryVo> slideshowList = this.slideshowService.queryAll();
        return Result.success(slideshowList);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Slideshow slideshow) {
        this.slideshowService.update(slideshow);
        return Result.success();
    }


    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        this.slideshowService.delete(id);
        return Result.success();
    }

    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        this.slideshowService.deleteBatch(ids);
        return Result.success();
    }
}
